Example 2D Visualizations Using the Iris Data


In [1]:
%pylab inline
from classy import *


Populating the interactive namespace from numpy and matplotlib
Keras not installed
Version:  0.0.19

In [2]:
data=load_excel('data/iris.xls',verbose=True)


iris.data 151 5
150 vectors of length 4
Feature names: 'petal length in cm', 'petal width in cm', 'sepal length in cm', 'sepal width in cm'
Target values given.
Target names: 'Iris-setosa', 'Iris-versicolor', 'Iris-virginica'
Mean:  [3.75866667 1.19866667 5.84333333 3.054     ]
Median:  [4.35 1.3  5.8  3.  ]
Stddev:  [1.75852918 0.76061262 0.82530129 0.43214658]

All possible 2D plots for features


In [3]:
plot_feature_combinations(data)


or choose which features to plot...


In [4]:
plot_feature_combinations(data,['petal length in cm','sepal width in cm','petal width in cm'])


Naive Bayes

since we're only interesting in viewing here, let's train with all the data, but just two features.


In [21]:
data_train=extract_features(data,[2,3])

In [22]:
C=NaiveBayes()

In [23]:
timeit(reset=True)
C.fit(data_train.vectors,data_train.targets)
print("Training time: ",timeit())


Time Reset
Training time:  0.0025658607482910156 seconds 

In [24]:
figure(figsize=(12,8))
plot2D(data_train,C,axis_range=[0,10.5,0,8])
C.plot_centers()  # plot the classifier information


kNearestNeighbor


In [25]:
C=kNearestNeighbor()

In [26]:
timeit(reset=True)
C.fit(data_train.vectors,data_train.targets)
print("Training time: ",timeit())


Time Reset
Training time:  0.0015039443969726562 seconds 

In [27]:
figure(figsize=(12,8))
plot2D(data_train,C,axis_range=[0,10.5,0,8])


RCE


In [28]:
C=RCE()

In [29]:
timeit(reset=True)
C.fit(data_train.vectors,data_train.targets)
print("Training time: ",timeit())


Time Reset
Training time:  0.27827882766723633 seconds 

In [30]:
print("number of centers:",len(C.centers))


number of centers: 76

In [31]:
figure(figsize=(12,8))
C.plot_centers()
plot2D(data_train,C,axis_range=[0,10.5,-1,8])


CSC


In [32]:
C=CSC()

In [33]:
timeit(reset=True)
C.fit(data_train.vectors,data_train.targets)
print("Training time: ",timeit())


Time Reset
Training time:  0.03620004653930664 seconds 

In [34]:
figure(figsize=(12,8))
C.plot_centers()
plot2D(data_train,C,axis_range=[0,10.5,-1,8])


Perceptron


In [ ]:
C=Perceptron()

In [35]:
timeit(reset=True)
C.fit(data_train.vectors,data_train.targets)
print(("Training time: ",timeit()))


Time Reset
('Training time: ', '0.03583693504333496 seconds ')

In [36]:
figure(figsize=(12,8))
plot2D(data_train,C,axis_range=[0,10.5,-1,8])


Backprop


In [44]:
C=BackProp(hidden_layer_sizes = [4],max_iter=10000,tol=1e-4)

In [45]:
timeit(reset=True)
C.fit(data_train.vectors,data_train.targets)
print(("Training time: ",timeit()))


Time Reset
('Training time: ', '0.7550270557403564 seconds ')

In [46]:
figure(figsize=(12,8))
plot2D(data_train,C,axis_range=[0,10.5,-1,8])



In [ ]: